package bayes.traversal;

import text.Text;
import text.TextSet;
import text.TextSetManager;
import text.traversal.ITextSetManagerTraversal;

public class GetBestClass implements ITextSetManagerTraversal
{
	private final Text text;
	
	private double bestProba = Double.POSITIVE_INFINITY;
	private TextSet bestClass;
	
	public void traversal(TextSet textSet, TextSetManager textSetManager)
	{	
		ComputeProbaClassOwner traversal = new ComputeProbaClassOwner(textSet);
		text.traversal(traversal);
		double proba = traversal.saveProbaClass(text);
		
		//System.out.println(text.getName() + " | " + textSet.getName() + " : " + proba + " [" + (this.bestClass==null?"/":this.bestClass.getName()) + " : " + this.bestProba + "]");
		
		if(proba < bestProba)
		{
			bestProba = proba;
			bestClass = textSet;
		}
	}
	
	public TextSet getBestClass()
	{
		return this.bestClass;
	}
	
	public GetBestClass(Text text)
	{
		this.text = text;
	}
}
